package com.sinaapp.gavinzhang.GSpider.plugin.concurrent;

import com.sinaapp.gavinzhang.GSpider.core.AbstractGWebUrlList;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 使用并发的已挖掘列表
 * Created by gavin on 15-8-7.
 */
public class ConcurrentVisitedUrlList extends AbstractGWebUrlList{
    private static final Object object = new Object();
    private ConcurrentHashMap<String,Object> concurrentHashMap;

    public ConcurrentVisitedUrlList() {
        this.concurrentHashMap = new ConcurrentHashMap<>();
    }

    @Override
    public boolean exist(String webUrl) {
        return concurrentHashMap.containsKey(webUrl);
    }

    //foundurl no use
    @Deprecated
    @Override
    public String get() {
        return null;
    }

    @Override
    public AbstractGWebUrlList add(String webUrl) {
        concurrentHashMap.put(webUrl,object);
        return this;
    }

    @Override
    public AbstractGWebUrlList remove(String webUrl) {
        concurrentHashMap.remove(webUrl);
        return this;
    }

    @Override
    public int size() {
        return concurrentHashMap.size();
    }
}
